Skip to content

Conversation

@qued
Copy link
Contributor

@qued qued commented Nov 18, 2025

Updated save_elements test to check the behavior of the environment variables EXTRACT_IMAGE_BLOCK_CROP_HORIZONTAL_PAD and EXTRACT_IMAGE_BLOCK_CROP_VERTICAL_PAD that pad the crop box for image extraction.


Note

Enhances save_elements tests to validate crop-box padding via env vars and image dimensions for both payload and file outputs; bumps version and updates changelog.

  • Tests (pdf_image_utils):
    • test_save_elements now parametrizes horizontal_padding/vertical_padding, sets EXTRACT_IMAGE_BLOCK_CROP_HORIZONTAL_PAD and EXTRACT_IMAGE_BLOCK_CROP_VERTICAL_PAD, and asserts padded image dimensions for both extract_image_block_to_payload paths (decoding image_base64 or reading saved file).
    • Adds required imports (base64, io).
  • Versioning:
    • Update unstructured/__version__.py to 0.18.21-dev0.
    • Add CHANGELOG entry noting the unit test enhancement.

Written by Cursor Bugbot for commit a23bf6a. This will update automatically on new commits. Configure here.

if horizontal_padding > 0:
monkeypatch.setenv("EXTRACT_IMAGE_BLOCK_CROP_HORIZONTAL_PAD", str(horizontal_padding))
if vertical_padding > 0:
monkeypatch.setenv("EXTRACT_IMAGE_BLOCK_CROP_VERTICAL_PAD", str(vertical_padding))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Env Var Leakage Breaks Test Isolation

Environment variables are only set conditionally when padding values are greater than 0. If EXTRACT_IMAGE_BLOCK_CROP_HORIZONTAL_PAD or EXTRACT_IMAGE_BLOCK_CROP_VERTICAL_PAD exist in the OS environment, test cases with padding=0 will incorrectly use those pre-existing values instead of 0, causing assertion failures. The variables need to be set unconditionally to ensure proper test isolation.

Fix in Cursor Fix in Web

@qued qued added this pull request to the merge queue Nov 18, 2025
Merged via the queue into main with commit 6c1bbb3 Nov 18, 2025
41 checks passed
@qued qued deleted the fix/pad-crop-box-doesnt-work-sometimes branch November 18, 2025 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants